package com.tianhao.luo.controller;

import com.tianhao.luo.configure.WeChatConfig;
import com.tianhao.luo.service.MessageService;
import com.tianhao.luo.utils.HttpUtil;
import com.tianhao.luo.utils.WeChatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author tianhao.luo
 * @date 2020/3/10 12:10
 */
@RestController
@RequestMapping("/test")
public class TestController {


    @Autowired
    private WeChatUtils weChatUtils;

    @Autowired
    private WeChatConfig weChatConfig;

    @Autowired
    private MessageService service;

    @PostMapping(value = "/check")
    public String messageMonitor(HttpServletRequest request) {
        return service.message(request);
    }
    @GetMapping
    public String test(){
        return weChatConfig.getToken();
    }

    @GetMapping("/check")
    public String checkLink(@RequestParam String signature,
                            @RequestParam String timestamp,
                            @RequestParam String nonce,
                            @RequestParam String echostr
                            ){
        return weChatUtils.checkLink(signature, timestamp, nonce, echostr);

    }

    @GetMapping("/access_token")
    public Object test2(){
        String tokenUrl = weChatConfig.getTokenUrl();
        return HttpUtil.get(tokenUrl);
    }
}
